package com.spodrum.balloon;

import java.util.Random;

import android.graphics.Color;
import android.graphics.Rect;

public class Balloon implements Comparable<Balloon>, UpdateableI
{
	private int x;
	private int y;
	private int width;
	private int height;
	private int colour;
	private Speed speed;
	
	private boolean popped;
	private Rect rect;
	
	private Random RND = new Random();
	
	public Balloon()
	{
		this(0,0,0,0);
	}
	
	public Balloon(int x, int y, int width, int height )
	{
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		setColour(Color.BLUE);
		this.rect = new Rect(x, y, x + width, y + height); 
		
		
		speed = new Speed(0, 3 + RND.nextInt(5));
	}
	
	public Balloon(int x, int y, int width, int height, int colour)
	{
		this(x, y, width, height);
		setColour(colour);
	}
	
	public Balloon(int x, int y, int width, int height, int colour, Speed speed)
	{
		this(x, y, width, height);
		setColour(colour);
		setSpeed(speed);
	}
	
	public void update()
	{
		x += (speed.getXv() * speed.getxDirection()); 
		y += (speed.getYv() * speed.getyDirection());
		updateRect();
	}
	
	public void updateRect()
	{
		getRect().set(x, y, x + width, y + height);
	}
	
	public float getX() 
	{
		return x;
	}

	public void setX(int x) 
	{
		this.x = x;
	}

	public float getY() 
	{
		return y;
	}

	public void setY(int y) 
	{
		this.y = y;
	}

	public int getWidth() 
	{
		return width;
	}

	public void setWidth(int width) 
	{
		this.width = width;
	}

	public int getHeight() 
	{
		return height;
	}

	public void setHeight(int height) 
	{
		this.height = height;
	}

	public boolean isPopped() 
	{
		return popped;
	}

	public void setPopped(boolean popped) 
	{
		this.popped = popped;
	}

	public int getColour()
	{
		return colour;
	}
	
	public void setColour(int colour)
	{
		this.colour = colour;
	}
	
	
	public Speed getSpeed() {
		return speed;
	}

	public void setSpeed(Speed speed) {
		this.speed = speed;
	}

	public Rect getRect()
	{
		return rect;
	}
	
	@Override
	public int compareTo(Balloon another) 
	{
		if(this.getSize() > another.getSize())
		{
			return 1;
		}
		else if(this.getSize() < another.getSize())
		{
			return -1;
		}
		
		return 0;
	}
	
	private int getSize()
	{
		return getWidth() * getHeight();
	}
}
